<template>
	<scroll-view class="home-list" scroll-y @scrolltolower="scroll" :refresher-triggered="triggered"
		:refresher-threshold="100" @refresherrestore="onRestore" refresher-enabled @refresherrefresh="onRefresh"
		:ower-threshold="0">
		<view class="home-list-item" :class="'type-' + item.approveStatus" v-for="(item, index) in arr" :key="index">
			<view class="item-dt">
				<text class="name u-line-1">{{ item.templateName }}</text>
			</view>
			<template v-if="item.planContent">
				<view class="item-box">
					<view :class="['item-dd',item.showMore?'showMore':'']">
						<text class="label" v-show="!item.showMore">{{item.planContent}}</text>
						<DetailCard v-show="item.showMore" :type="item.templateName.includes('预警')?'warning':'notice'"
							:rowDetail="item"></DetailCard>
					</view>
				</view>
				<view class="more" @click.stop="clickMore(index)">
					<text>显示更多</text>
					<view class="icon" :style="{ top: item.showMore ? '10px' : '7px' }">
						<uni-icons style="top: 14rpx" :type="item.showMore ? 'top' : 'bottom'" size="14" color="#999" />
					</view>
				</view>
			</template>
			<template v-else>
				<Empty />
			</template>
		</view>
		<view class="loading animation-scale-up" v-if="loading"></view>
		<view class="scroll-no-data" v-if="scrollNoData">已拉到最底部</view>
	</scroll-view>
</template>

<script>
	import {
		setPageData
	} from "@/store/user";
	import Empty from "@/components/empty";
	import {
		setToken,
		getToken,
		getUserInfo,
		getNotice
	} from "@/store/user.js";
	import DetailCard from './checkDetail';
	export default {
		components: {
			Empty,
			DetailCard
		},
		props: {
			data: {
				type: Array,
				default: [],
			},
			scrollNoData: {
				type: Boolean,
				default: false,
			},
			type: {
				type: String,
				default: "1", //1 块点击  2里面的内容行点击
			},
		},
		watch: {
			data: {
				handler: function(val, oldVal) {
					this.arr = val;
				},
				deep: true,
				immediate: true,
			},
		},
		data() {
			return {
				loading: true,
				noData: false,
				arr: [],
				triggered: false,
			};
		},
		onReady: async function() {},
		onPullDownRefresh() {
			uni.stopPullDownRefresh();
		},
		mounted() {},
		methods: {
			clickMore(index) {
				this.$set(this.arr, index, {
					...this.arr[index],
					showMore: !this.arr[index].showMore,
				});
			},
			setLoading(val) {
				this.loading = val;
			},
			scroll(e) {
				const that = this;
				if (!that.noData) {
					this.loading = true;
					this.$emit("scrollBottom", (val) => {
						that.noData = val;
						setTimeout(() => {
							this.loading = false;
						}, 400);
					});
				}
			},
			onRefresh() {
				if (this._freshing) return;
				this._freshing = true;
				this.triggered = true;
				this.$emit("onRefresh");
				setTimeout(() => {
					this.triggered = false;
					this._freshing = false;
				}, 1000);
			},
			onRestore() {
				this.triggered = "restore"; // 需要重置
			},
			// itemClick2(item) {
			//   if (this.type == "1") return;
			//   setPageData(item);
			//   this.$emit("itemClick", item);
			// },
			qrCodeClick(data) {
				// this.$emit("qrCodeClick", item);
				setPageData(data);
				uni.navigateTo({
					url: "/pages/qrCode/index",
					animationType: "pop-in",
				});
			},
			ok(val) {
				this.$emit("ok", val);
			},
		},
	};
</script>

<style lang="scss" scoped>
	.home-list {
		height: 100%;

		.home-list-item {
			padding-top: 16rpx;
			background-color: #fff;
			box-shadow: 0rpx 5rpx 13rpx 1rpx #e0e0e0;
			margin-bottom: 20rpx;
			border-radius: 10px;
			overflow: hidden;
			position: relative;
			min-height: 300rpx;
			display: flex;
			flex-direction: column;

			.item-dt {
				padding: 0 30rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 20rpx;

				.u-line-1 {
					font-size: 1.5rem !important;
				}

				.name {
					font-size: 20px;
					min-width: 50%;
					flex: 1;
				}

				.view {
					color: #83b4ff;
					display: flex;
					align-items: center;
					overflow: auto;

					.tag-item {
						font-size: 14px;
					}

					.tag-item:last-child {
						margin-right: 0;
					}
				}
			}

			.item-box {
				padding: 0 30rpx;
				display: flex;
				flex: 1;
				margin-bottom: 20rpx;
			}

			.showMore {
				height: auto !important;
				display: flex !important;
				flex: 1 !important;
			}

			.item-dd {
				justify-content: space-between;
				overflow: hidden;
				// flex: 1;
				height: 129rpx;
				word-break: break-all;
				white-space: normal;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 3;
				/* 2行后省略号 *

	    text-overflow: ellipsis; /* 显示省略号 */

				margin-right: 20rpx;

				.label {
					margin-right: 10rpx;
					font-size: 1.2rem;
					width: 100%;
				}

				.value {
					font-size: 28rpx;
					flex: 1;
					overflow: hidden;
				}

				.btn {
					width: 170rpx;
					min-width: 170rpx;
					margin-left: 29rpx;
					height: 60rpx;
					color: #fff;
					font-size: 24rpx;
				}
			}

			.tag-box {
				display: flex;
				align-items: center;

				.tag {
					margin-right: 5rpx;
				}
			}
		}

		.progress {
			position: absolute;
			right: 10rpx;
			bottom: 56rpx;
			width: 30%;
		}

		.item-bottom {
			height: 64rpx;
			line-height: 64rpx;
			padding: 0 37rpx;
			background-color: #b8c6b7;
			display: flex;
			align-items: center;
			justify-content: flex-end;

			.img {
				width: 47rpx;
				height: 37rpx;
				margin-right: 24rpx;
			}
		}

		.scroll-no-data {
			text-align: center;
		}

		.more {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-bottom: 10rpx;
			color: #666;
		}
	}
</style>